package org.vectrics.recruiter.struts.tag;

import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.common.html.Table;
import org.vectrics.company.Company;
import org.vectrics.company.CompanyPerson;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class UserBufferForCompanyTag extends UserBufferTag {

	private static final long serialVersionUID = -9209055718656401234L;
	
	private transient final Logger log = Logger.getLogger(this.getClass());
    private String companyId = null;
    
    public UserBufferForCompanyTag() {
    	super();
    }
    
    private Company getCompany() {
        Company company = CoreServiceLocator.getCompanyService().findCompany(new Long(companyId));
        return(company);
    }
    
    protected void createJobBufferContent(Table contentTable, Job jobForBuffer) {
        
    }
    
    protected void createPersonBufferContent(Table contentTable, Person personForBuffer) {
        CompanyPerson companyPerson = CoreServiceLocator.getCompanyService().findCompanyPerson(getCompany(), personForBuffer);
        if (companyPerson == null) {
	    	String href = this.getContextPath() + "/admin/company/person/add.do?companyId=" 
	    			+ getCompany().getId() + "&personId=" + personForBuffer.getId();
	    	this.makeLinkRow(contentTable, this.getPhrase("phrase.company.add.person"), href);
        } else {
            log.debug("Person is already attached to company, no link");
        }
    	
    }

    protected void createCompanyBufferContent(Table contentTable, Company companyForBuffer) {
    }
    
	/**
	 * @return Returns the companyId.
	 */
	public String getCompanyId() {
		return companyId;
	}
	
	/**
	 * @param companyId The companyId to set.
	 */
	public void setCompanyId(String companyId) {
		if (companyId == null) {
			throw new SystemException("Company ID is null for user buffer for company ");
		}
		this.companyId = companyId;
	}
	
}
